package com.momo.cloudspringserver.feign;

import com.momo.cloudspringserver.configuration.FeignConfiguration;
import com.momo.cloudspringserver.entity.SysUser;
import com.momo.cloudspringserver.utils.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @program: momo-cloud
 * @description: feign调用  name对应服务名称
 * @author: Jie Li
 * @create: 2019-07-16 16:59
 **/
@FeignClient(name = "cloud-spring-server", configuration = {FeignConfiguration.class}, fallback = FeignService.FeignServiceImpl.class)
public interface FeignService {
    @PostMapping(value = "/platform/userInfo/v1", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public JSONResult getUserInfo(@RequestBody SysUser sysUser);

    @Component
    @Slf4j
    static class FeignServiceImpl implements FeignService {
        @Override
        public JSONResult getUserInfo(SysUser sysUser) {
            log.error("feign调用异常:");
            return JSONResult.errorMap("feign调用异常");
        }
    }
}
